<template>
  <div>
    <el-card>
      <el-table :data="table.tableData" style="width: 100%">
        <el-table-column prop="attendanceTime" label="考核月份"></el-table-column>
        <el-table-column prop="stutasStr" label="考核阶段"></el-table-column>
        <el-table-column prop="empName" label="姓名"></el-table-column>
        <el-table-column prop="empStatuStr" label="绩效填写状态"></el-table-column>
        <el-table-column prop="score" label="分数"></el-table-column>
        <el-table-column label="操作" width="230px">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              v-if="scope.row.stutas==1 && scope.row.empStatus==0"
              @click="openAddMonthPlanPage(scope.row.id,scope.row.attEmpId)"
            >填写月初计划</el-button>
            <el-button
              type="text"
              size="small"
              v-if="scope.row.stutas==1 && scope.row.empStatus==1"
              @click="openUpdateMonthPlanPage(scope.row.id,scope.row.empId)"
            >修改月初计划</el-button>
            <el-button
              type="text"
              size="small"
              v-if="scope.row.stutas==1 && scope.row.empStatus==1"
              @click="submitMonthPlan(scope.row.id,scope.row.empId)"
            >提交月初计划</el-button>

            <el-button
              type="text"
              size="small"
              v-if="scope.row.stutas==3 && scope.row.empStatus==2"
              @click="openAddCommitAttendancePage(scope.row.id,scope.row.attEmpId)"
            >填写绩效</el-button>
            <el-button
              type="text"
              size="small"
              v-if="scope.row.stutas==3 && scope.row.empStatus==3"
              @click="openUpdateCommitAttendancePage(scope.row.id,scope.row.empId)"
            >修改绩效</el-button>
            <el-button
              type="text"
              size="small"
              v-if="scope.row.stutas==3 && scope.row.empStatus==3"
              @click="submitAttendance(scope.row.id,scope.row.empId)"
            >提交绩效</el-button>
            <el-button
              type="text"
              size="small"
              v-if="scope.row.stutas==3 && scope.row.empStatus==4"
              @click="openMarkSelfPage(scope.row.id,scope.row.attEmpId)"
            >自评</el-button>

            <el-button
              type="text"
              size="small"
              @click="showAllCommits(scope.row.id,scope.row.empId)"
              v-if="scope.row.empStatus !=0 && scope.row.empStatus !=1"
            >查看月计划/绩效</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        small
        layout="prev, pager, next"
        :total="this.table.tableTotal"
        :page-size="this.table.pageSize"
        @current-change="pagenationChange"
        @prev-click="pagenationChange"
        @next-click="pagenationChange"
      ></el-pagination>
    </el-card>
    <!--添加月计划-->
    <el-dialog
      title="填写月计划"
      :visible.sync="dialogAddMonthPlanVisible"
      width="60%"
      @closed="CloseAddMonthPlanPage"
    >
      <el-form :model="addMonthPlanForm" ref="addMonthPlanForm" label-width="100px">
        <div v-for="(item,index) in addMonthPlanForm.addMonthPlanItems" :key="index">
          <el-form-item
            :label="'起止时间'+index"
            :prop="'addMonthPlanItems.'+index+'.startAndEndDate'"
            :rules="{required:true,message:'起止时间不能为空',trigger:'blur'}"
          >
            <el-date-picker
              v-model="item.startAndEndDate"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              size="small"
            ></el-date-picker>
          </el-form-item>
          <el-form-item
            :label="'工作重点' + index"
            :key="index"
            :prop="'addMonthPlanItems.' + index + '.workInfo'"
            :rules="{required: true, message: '工作重点不能为空', trigger: 'blur'}"
          >
            <el-row :gutter="10">
              <el-col :span="19">
                <el-input v-model="item.workInfo" type="textarea" :autosize="{minRows:4}"></el-input>
              </el-col>
              <el-col :span="1">
                <el-button @click.prevent="removeAddPlanItem(item)">删除</el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </div>

        <el-form-item>
          <el-button type="primary" :disabled="saveMonthPlanBtn" @click="saveMonthPlan">保存</el-button>
          <el-button type="primary" @click="addAddPlanItem">新增选项</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--修改月计划-->
    <el-dialog title="修改月计划" :visible.sync="dialogUpdateMonthPlanVisible" width="60%">
      <el-form :model="updateMonthPlanForm" ref="updateMonthPlanForm" label-width="100px">
        <div v-for="(item,index) in updateMonthPlanForm.updateMonthPlanItems" :key="index">
          <el-form-item
            :label="'起止时间'+index"
            :prop="'updateMonthPlanItems.'+index+'.startAndEndDate'"
            :rules="{required:true,message:'起止时间不能为空',trigger:'blur'}"
          >
            <el-date-picker
              v-model="item.startAndEndDate"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              size="small"
            ></el-date-picker>
          </el-form-item>
          <el-form-item
            :label="'工作重点' + index"
            :key="index"
            :prop="'updateMonthPlanItems.' + index + '.workInfo'"
            :rules="{required: true, message: '工作重点不能为空', trigger: 'blur'}"
          >
            <el-row :gutter="10">
              <el-col :span="21">
                <el-input v-model="item.workInfo" type="textarea" :autosize="{minRows:4}"></el-input>
              </el-col>
              <el-col :span="1">
                <el-button @click.prevent="removeUpdatePlanItem(item)">删除</el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </div>

        <el-form-item>
          <el-button type="primary" @click="updateMonthPlan">保存</el-button>
          <el-button type="primary" @click="addUpdatePlanItem">新增选项</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!--添加绩效-->
    <el-dialog
      title="填写月绩效"
      :visible.sync="dialogAddAttendanceVisible"
      width="60%"
      @closed="closeAddAddAttendancePage"
    >
      <el-form :model="addAttendanceForm" ref="addAttendanceForm" label-width="100px">
        <div v-for="(item,index) in addAttendanceForm.addAttendanceItems" :key="index">
          <el-form-item
            :label="'起止时间'+index"
            :prop="'addAttendanceItems.'+index+'.startAndEndDate'"
            :rules="{required:true,message:'起止时间不能为空',trigger:'blur'}"
          >
            <el-date-picker
              v-model="item.startAndEndDate"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              size="small"
            ></el-date-picker>
          </el-form-item>
          <el-form-item
            :label="'完成时间'+index"
            :prop="'addAttendanceItems.'+index+'.finishDate'"
            :rules="{required:true,message:'完成时间不能为空',trigger:'blur'}"
          >
            <el-date-picker
              v-model="item.finishDate"
              autosize
              size="small"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item
            :label="'完成目标'+index"
            :prop="'addAttendanceItems.'+index+'.target'"
            :rules="{required:true,message:'请填写完成目标',trigger:'blur'}"
          >
            <el-input v-model="item.target" size="small"></el-input>
          </el-form-item>
          <el-form-item
            :label="'完成结果'+index"
            :prop="'addAttendanceItems.'+index+'.finishResult'"
            :rules="{required:true,message:'请现在完成结果',trigger:'blur'}"
          >
            <el-select v-model="item.finishResult" placeholder="请选择完成结果" size="small">
              <el-option key="1" label="提前完成超出标准" value="1"></el-option>
              <el-option key="2" label="按时完成超出标准" value="2"></el-option>
              <el-option key="3" label="按时完成达到标准" value="3"></el-option>
              <el-option key="4" label="按时完成不标准" value="4"></el-option>
              <el-option key="5" label="未完成" value="5"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item
            :label="'工作重点' + index"
            :key="index"
            :prop="'addAttendanceItems.' + index + '.workInfo'"
            :rules="{required: true, message: '工作重点不能为空', trigger: 'blur'}"
          >
            <el-row :gutter="10">
              <el-col :span="19">
                <el-input v-model="item.workInfo" type="textarea" :autosize="{minRows:4}"></el-input>
              </el-col>
              <el-col :span="1">
                <el-button @click.prevent="removeAddPlanItem(item)">删除</el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </div>

        <el-form-item>
          <el-button type="primary" :disabled="saveMAttendanceBtn" @click="saveMAttendance">保存</el-button>
          <el-button type="primary" @click="addAttendanceItem">新增选项</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--修改绩效-->
    <el-dialog title="修改月绩效" :visible.sync="dialogUpdateAttendanceVisible" width="60%">
      <el-form :model="updateAttendanceForm" ref="updateAttendanceForm" label-width="100px">
        <div v-for="(item,index) in updateAttendanceForm.updateAttendanceItems" :key="index">
          <el-form-item
            :label="'起止时间'+index"
            :prop="'updateAttendanceItems.'+index+'.startAndEndDate'"
            :rules="{required:true,message:'起止时间不能为空',trigger:'blur'}"
          >
            <el-date-picker
              v-model="item.startAndEndDate"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              size="small"
            ></el-date-picker>
          </el-form-item>
          <el-form-item
            :label="'完成时间'+index"
            :prop="'updateAttendanceItems.'+index+'.finishDate'"
            :rules="{required:true,message:'完成时间不能为空',trigger:'blur'}"
          >
            <el-date-picker
              v-model="item.finishDate"
              autosize
              size="small"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item
            :label="'完成目标'+index"
            :prop="'updateAttendanceItems.'+index+'.target'"
            :rules="{required:true,message:'请填写完成目标',trigger:'blur'}"
          >
            <el-input v-model="item.target" size="small"></el-input>
          </el-form-item>
          <el-form-item
            :label="'完成结果'+index"
            :prop="'updateAttendanceItems.'+index+'.finishResult'"
            :rules="{required:true,message:'请现在完成结果',trigger:'blur'}"
          >
            <el-select v-model="item.finishResult" placeholder="请选择完成结果" size="small">
              <el-option key="1" label="提前完成超出标准" value="1"></el-option>
              <el-option key="2" label="按时完成超出标准" value="2"></el-option>
              <el-option key="3" label="按时完成达到标准" value="3"></el-option>
              <el-option key="4" label="按时完成不标准" value="4"></el-option>
              <el-option key="5" label="未完成" value="5"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item
            :label="'工作重点' + index"
            :key="index"
            :prop="'updateAttendanceItems.' + index + '.workInfo'"
            :rules="{required: true, message: '工作重点不能为空', trigger: 'blur'}"
          >
            <el-row :gutter="10">
              <el-col :span="19">
                <el-input v-model="item.workInfo" type="textarea" :autosize="{minRows:4}"></el-input>
              </el-col>
              <el-col :span="1">
                <el-button @click.prevent="removeAddAttendanceItem(item)">删除</el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </div>

        <el-form-item>
          <el-button type="primary" @click="updateMAttendance">保存</el-button>
          <el-button type="primary" @click="addUpdateAttendanceItem">新增选项</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--自评-->
    <el-dialog title="自评" :visible.sync="dialogMarkSelfVisible" width="45%">
      <el-form label-width="140px" ref="markSelfForm" :model="markSelfForm">
        <div v-for="(item,index) in markSelfForm.tempItems" :key="index">
          <el-form-item
            :label="item.attendanceItemName"
            :prop="'tempItems.'+index+'.score'"
            :rules="{required:true,message:'分数必填',trigger:'blur'}"
          >
            <el-input-number v-model="item.score" :precision="2" :step="5" :max="100" :min="0"></el-input-number>
          </el-form-item>
        </div>
        <el-form-item>
          <el-button type="primary" :disabled="saveMarkSelfBtn" @click="saveMarkSelf">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      corpId: null,
      table: {
        tableData: null,
        pageIndex: 1,
        pageSize: 10,
        tableTotal: null
      },
      currentEmpId: null,
      currentItemId: null, //当前选中的行的考核id
      currentAttEmpId: null, //当前选中的行的人员考核id
      dialogAddMonthPlanVisible: false,
      saveMonthPlanBtn: false,
      //-----------添加初计划
      addMonthPlanForm: {
        attendaceEmpId: null,
        addMonthPlanItems: [
          {
            startAndEndDate: null,
            workInfo: "",
            type: 1,
            startDate: null,
            endDate: null,
            empId: null,
            attendanceId: null
          }
        ]
      },
      //-----------修改月初计划部分
      dialogUpdateMonthPlanVisible: false,
      updateMonthPlanForm: {
        updateMonthPlanItems: [
          {
            id: null,
            startAndEndDate: null,
            attendanceId: null,
            empId: null,
            worktime: null,
            workInfo: null,
            finishDate: null,
            target: null,
            finishResult: null,
            empStatus: null,
            itemStutas: null,
            finishResultStr: null
          }
        ]
      },
      //---------------添加绩效
      dialogAddAttendanceVisible: false,
      saveMAttendanceBtn: false,
      addAttendanceForm: {
        attendaceEmpId: null,
        addAttendanceItems: [
          {
            startDate: null,
            endDate: null,
            workInfo: null,
            finishDate: null,
            target: null,
            finishResult: null,
            empId: null,
            type: 2
          }
        ]
      },
      //------------------修改绩效
      dialogUpdateAttendanceVisible: false,
      updateAttendanceForm: {
        updateAttendanceItems: []
      },
      //-----------------自评
      dialogMarkSelfVisible: false,
      saveMarkSelfBtn: false,
      markSelfForm: {
        tempItems: [{ id: null, attendanceItemName: null, score: null }]
      }
    };
  },
  created: function() {
    this.getJsApiTeckit();
  },
  methods: {
    //查询签名信息
    async getJsApiTeckit() {
      var result = await this.$httpd.get("/DingDingSecurity/GetJsapiTicket");
      if (result.status != 200) {
        this.$message.error("获取钉钉信息出错");
        return;
      }
      this.corpId = result.data.corpId;
      this.getCode(result.data.corpId);
    },
    //获取当前登录者的code
    getCode(corpId) {
      var that = this;
      that.$dd.ready(() => {
        that.$dd.runtime.permission.requestAuthCode({
          corpId: corpId, // 企业id
          onSuccess: function(info) {
            that.GetCurrentEmp(info.code);
          }
        });
      });
    },
    //获取当前登录者的id
    async GetCurrentEmp(code) {
      var result = await this.$httpd.get(
        `/DingDingSecurity/GetuserInfo?code=${code}`
      );
      this.currentEmpId = result.data.userid;
      this.queryAttendanceEmpSelf(this.currentEmpId);
    },
    //获取table表的数据
    async queryAttendanceEmpSelf(empId) {
      var result = await this.$httpd.post(
        "/AttendanceEmp/QueryAttendanceEmpSelf",
        {
          pageIndex: this.table.pageIndex,
          pageSize: this.table.pageSize,
          empid: empId
        }
      );
      this.table.tableData = result.data.data.data;
      this.table.tableTotal = result.data.data.total;
    },
    //分页条件改变
    pagenationChange(pageIndex) {
      this.table.pageIndex = pageIndex;
      this.queryAttendanceEmpSelf(this.currentEmpId);
    },
    //打开填写月计划的页面
    openAddMonthPlanPage(itemId, attEmpId) {
      this.dialogAddMonthPlanVisible = true;
      this.saveMonthPlanBtn = false;
      this.currentItemId = itemId;
      this.currentAttEmpId = attEmpId;
    },
    //保存月计划
    saveMonthPlan() {
      this.$refs.addMonthPlanForm.validate(async v => {
        if (v) {
          this.saveMonthPlanBtn = true;
          this.addMonthPlanForm.attendaceEmpId = this.currentAttEmpId;
          this.addMonthPlanForm.addMonthPlanItems.forEach(element => {
            element.startDate = element.startAndEndDate[0];
            element.endDate = element.startAndEndDate[1];
            element.attendanceId = this.currentItemId;
            element.empId = this.currentEmpId;
            element.type = 1;
          });
          var result = await this.$httpd.post(
            "/AttendanceCommint/Add",
            this.addMonthPlanForm
          );
          if (result.status != 200 || result.data.returnStatus == 0) {
            this.$message.error(result.data.message);
            return;
          }
          //关闭弹窗
          this.dialogAddMonthPlanVisible = false;
          //刷新列表
          this.queryAttendanceEmpSelf(this.currentEmpId);
          this.CloseAddMonthPlanPage();
          this.$message.success({
            message: result.data.message,
            type: "success"
          });
        }
      });
    },
    //修改月计划
    updateMonthPlan() {
      this.$refs.updateMonthPlanForm.validate(async v => {
        if (v) {
          this.updateMonthPlanForm.updateMonthPlanItems.forEach(element => {
            element.startDate = element.startAndEndDate[0];
            element.endDate = element.startAndEndDate[1];
            element.attendanceId = this.currentItemId;
            element.empId = this.currentEmpId;
            element.type = 1;
          });

          var result = await this.$httpd.post(
            "/AttendanceCommint/Update",
            this.updateMonthPlanForm
          );
          if (result.status != 200 || result.data.returnStatus == 0) {
            this.$message.error(result.data.message);
            return;
          }
          //关闭弹窗
          this.dialogUpdateMonthPlanVisible = false;
          this.$message.success({
            message: result.data.message,
            type: "success"
          });
        }
      });
    },
    //添加选项
    addAddPlanItem() {
      this.addMonthPlanForm.addMonthPlanItems.push({
        startAndEndDate: null,
        workInfo: ""
      });
    },
    //删除选项
    removeAddPlanItem(item) {
      var index = this.addMonthPlanForm.addMonthPlanItems.indexOf(item);
      if (index == 0) {
        this.$message.error("至少填写一周的计划");
        return;
      }
      if (index !== -1) {
        this.addMonthPlanForm.addMonthPlanItems.splice(index, 1);
      }
    },
    //添加修改页面的选项
    addUpdatePlanItem() {
      this.updateMonthPlanForm.updateMonthPlanItems.push({
        startAndEndDate: null,
        workInfo: ""
      });
    },
    //删除修改页面的选项
    removeUpdatePlanItem(item) {
      var index = this.updateMonthPlanForm.updateMonthPlanItems.indexOf(item);
      if (index == 0) {
        this.$message.error("至少填写一周的计划");
        return;
      }
      if (index !== -1) {
        this.updateMonthPlanForm.updateMonthPlanItems.splice(index, 1);
      }
    },
    //关闭添加页面
    CloseAddMonthPlanPage() {
      this.$refs.addMonthPlanForm.resetFields();
    },
    //打开修改月计划的页面
    async openUpdateMonthPlanPage(itemId, empId) {
      this.dialogUpdateMonthPlanVisible = true;
      this.currentItemId = itemId;
      this.currentAttEmpId = empId;
      var result = await this.$httpd.get(
        `/AttendanceCommint/QueryAttendanceCommints?attid=${itemId}&empId=${empId}`
      );
      if (result.status != 200 || result.data.returnStatus == 0) {
        this.$message.error(result.data.message);
        return;
      }
      this.updateMonthPlanForm.updateMonthPlanItems = result.data.data;
      this.updateMonthPlanForm.updateMonthPlanItems.forEach(el => {
        el.startAndEndDate = [el.startDate, el.endDate];
      });
    },
    //提交月计划
    async submitMonthPlan(itemId, attenEmpId) {
      var result = await this.$httpd.post(
        "/AttendanceEmp/AttendanceEmpChanageStatus",
        {
          AttendanceItemId: itemId,
          EmpId: attenEmpId,
          Status: 2
        }
      );
      if (result.status != 200 || result.data.returnStatus == 0) {
        this.$message.error(result.data.message);
        return;
      }
      //刷新列表
      this.queryAttendanceEmpSelf(this.currentEmpId);
      this.$message.success({
        message: result.data.message,
        type: "success"
      });
    },
    //提交绩效
    async submitAttendance(itemId, attenEmpId) {
      var result = await this.$httpd.post(
        "/AttendanceEmp/AttendanceEmpChanageStatus",
        {
          AttendanceItemId: itemId,
          EmpId: attenEmpId,
          Status: 4
        }
      );
      if (result.status != 200 || result.data.returnStatus == 0) {
        this.$message.error(result.data.message);
        return;
      }
      //刷新列表
      this.queryAttendanceEmpSelf(this.currentEmpId);
      this.$message.success({
        message: result.data.message,
        type: "success"
      });
    },
    //查看绩效
    showAllCommits(itemId, empId) {
      this.$router.push({
        name: "attendanceCommitAll",
        params: {
          eid: empId,
          attendanceId: itemId
        }
      });
    },
    //-------------------------------绩效部分
    //打开添加绩效页面
    openAddCommitAttendancePage(itemId, attEmpId) {
      this.dialogAddAttendanceVisible = true;
      this.saveMAttendanceBtn = false;
      this.currentItemId = itemId;
      this.currentAttEmpId = attEmpId;
    },
    //关闭添加绩效页面事件
    closeAddAddAttendancePage() {
      this.$refs.addAttendanceForm.resetFields();
    },
    addAttendanceItem() {
      this.addAttendanceForm.addAttendanceItems.push({
        startAndEndDate: null,
        workInfo: ""
      });
    },
    saveMAttendance() {
      this.$refs.addAttendanceForm.validate(async v => {
        if (v) {
          this.saveMAttendanceBtn = true;
          //this.addAttendanceForm.attendaceEmpId = this.currentAttEmpId;
          this.addAttendanceForm.addAttendanceItems.forEach(element => {
            element.startDate = element.startAndEndDate[0];
            element.endDate = element.startAndEndDate[1];
            element.attendanceId = this.currentItemId;
            element.empId = this.currentEmpId;
            element.type = 2;
            element.finishResult = parseInt(element.finishResult);
          });
          var result = await this.$httpd.post("/AttendanceCommint/Add", {
            attendaceEmpId: this.currentAttEmpId,
            addMonthPlanItems: this.addAttendanceForm.addAttendanceItems
          });
          if (result.status != 200 || result.data.returnStatus == 0) {
            this.$message.error(result.data.message);
            return;
          }
          //关闭弹窗
          this.dialogAddAttendanceVisible = false;
          //刷新列表
          this.queryAttendanceEmpSelf(this.currentEmpId);
          this.closeAddAddAttendancePage();
          this.$message.success({
            message: result.data.message,
            type: "success"
          });
        }
      });
    },
    //修改绩效
    async openUpdateCommitAttendancePage(itemId, empId) {
      this.dialogUpdateAttendanceVisible = true;
      this.currentItemId = itemId;
      this.currentAttEmpId = empId;
      var result = await this.$httpd.get(
        `/AttendanceCommint/QueryAttendanceCommints?attid=${itemId}&empId=${empId}`
      );
      if (result.status != 200 || result.data.returnStatus == 0) {
        this.$message.error(result.data.message);
        return;
      }
      this.updateAttendanceForm.updateAttendanceItems = result.data.data;
      this.updateAttendanceForm.updateAttendanceItems.forEach(el => {
        el.startAndEndDate = [el.startDate, el.endDate];
        el.finishResult = el.finishResult + "";
      });
    },
    //删除绩效项目
    removeAddAttendanceItem(item) {
      var index = this.updateAttendanceForm.updateAttendanceItems.indexOf(item);
      if (index === 0) {
        this.$message.error("至少添加一条绩效");
        return;
      }
      if (index !== -1) {
        this.updateAttendanceForm.updateAttendanceItems.splice(index, 1);
      }
    },
    //添加修改绩效项目
    addUpdateAttendanceItem() {
      this.updateAttendanceForm.updateAttendanceItems.push({
        startAndEndDate: null,
        workInfo: ""
      });
    },
    //修改绩效
    updateMAttendance() {
      this.$refs.updateAttendanceForm.validate(async v => {
        if (v) {
          this.updateAttendanceForm.updateAttendanceItems.forEach(element => {
            element.startDate = element.startAndEndDate[0];
            element.endDate = element.startAndEndDate[1];
            element.attendanceId = this.currentItemId;
            element.empId = this.currentEmpId;
            element.type = 2;
            element.finishResult = parseInt(element.finishResult);
          });

          var result = await this.$httpd.post("/AttendanceCommint/Update", {
            updateMonthPlanItems: this.updateAttendanceForm
              .updateAttendanceItems
          });
          if (result.status != 200 || result.data.returnStatus == 0) {
            this.$message.error(result.data.message);
            return;
          }
          //关闭弹窗
          this.dialogUpdateAttendanceVisible = false;
          this.$message.success({
            message: result.data.message,
            type: "success"
          });
        }
      });
    },
    //打开自评页面
    openMarkSelfPage(itemId, attEmpId) {
      this.currentItemId = itemId;
      this.currentAttEmpId = attEmpId;
      this.dialogMarkSelfVisible = true;
      this.saveMarkSelfBtn = false;
      var that = this;
      that.$dd.ready(() => {
        that.$dd.runtime.permission.requestAuthCode({
          corpId: that.corpId, // 企业id
          onSuccess: function(info) {
            that.getDepart(info.code);
          }
        });
      });
    },
    //获取部门信息
    async getDepart(code) {
      var result = await this.$httpd.get(
        `/EmpSalary/GetdepartmentById?code=${code}`
      );
      if (result.status != 200) {
        this.$message.error("获取部门数据出错");
        return;
      }
      var departId = result.data.isAdmin
        ? result.data.id
        : result.data.parentid;
      this.getAttendanceItems(departId);
    },
    //获取考勤模板列表
    async getAttendanceItems(departId) {
      var result = await this.$httpd.get(
        `/AttendanceTemplate/QueryAttendanceTemplates?dePartId=${departId}`
      );
      if (result.status != 200) {
        this.$message.error("获取考勤模板数据出错");
        return;
      }
      this.markSelfForm.tempItems = result.data.data;
    },
    //保存自评
    async saveMarkSelf() {
      this.$refs.markSelfForm.validate(async v => {
        if (v) {
          this.saveMarkSelfBtn = true;
          var markSelfData = { attEmpid: null, resultAddInputs: [] };
          markSelfData.attEmpid = this.currentAttEmpId;
          this.markSelfForm.tempItems.forEach(e => {
            markSelfData.resultAddInputs.push({
              attendanceEmpId: this.currentEmpId, //用户id
              attendanceTempId: e.id, //模板id
              SelfScore: e.score,
              attendanceItemId: this.currentItemId
            });
          });
          var result = await this.$httpd.post(
            "/AttendanceEmpResultAdd/Add",
            markSelfData
          );
          if (result.status != 200 || result.data.returnStatus == 0) {
            this.$message.error(result.data.message);
            return;
          }
          this.dialogMarkSelfVisible = false;
          this.queryAttendanceEmpSelf(this.currentEmpId);
          this.$message.success({
            message: result.data.message,
            type: "success"
          });
        }
      });
    }
  }
};
</script>
<style scoped>
.el-pagination {
  margin-top: 20px;
  text-align: center;
}
</style>